package com.roden.study.java.util;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @Author luod
 * @create 2022/7/2 11:21
 */
public class CollectionsTest {
    /**
     * 排序
     */
    @Test
    public void sort(){
        List<Integer> list = new ArrayList<>();
        list.add(2);
        list.add(1);
        list.add(3);
        Collections.sort(list);//升序
        System.out.println(list);
        Collections.reverse(list);//降序
        System.out.println(list);
    }

    /**
     * 获取最大或最小值
     */
    @Test
    public void minOrMax(){
        List<Integer> list = new ArrayList<>();
        list.add(2);
        list.add(1);
        list.add(3);
        Integer max = Collections.max(list);//获取最大值
        Integer min = Collections.min(list);//获取最小值
        System.out.println(max);
        System.out.println(min);

    }

    /**
     * 转换线程安全集合
     */
    @Test
    public void synchronizedList(){
        List<Integer> list = new ArrayList<>();
        list.add(2);
        list.add(1);
        list.add(3);
        List<Integer> integers = Collections.synchronizedList(list);//将ArrayList转换成线程安全集合
        System.out.println(integers);
    }
}
